package mo.tags.greedy;

public class L921 {

    public int minAddToMakeValid(String s) {
        int leftCount = 0;
        int addCount = 0;
        for (char c : s.toCharArray()) {
            if (c == '(') {
                leftCount++;
            } else {
                if (leftCount == 0) {
                    addCount++;
                } else {
                    leftCount--;
                }
            }
        }
        return addCount + leftCount;
    }

}
